namespace OpenWeb.Dal.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            //System.Data.Entity.CreateDatabaseIfNotExists
                //System.Data.Entity.Migrations
            
            //AlterColumn();
            
            CreateTable(
                "dbo.Contact",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        IsCustomer = c.Boolean(),
                        IsPerson = c.Boolean(),
                        ContactType = c.Int(),
                        Pref = c.String(maxLength: 6),
                        Name = c.String(maxLength: 50),
                        Surname = c.String(maxLength: 50),
                        Description = c.String(maxLength: 300),
                        Notes = c.String(maxLength: 200),
                        Email = c.String(maxLength: 50),
                        Tel1 = c.String(maxLength: 20),
                        Tel2 = c.String(maxLength: 20),
                        Cell = c.String(maxLength: 20),
                        Fax = c.String(maxLength: 20),
                        WebSite = c.String(maxLength: 50),
                        DateCreation = c.DateTime(),
                        Guid = c.Guid(nullable: false),
                        IsDeleted = c.Boolean(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.ContactProfile",
                c => new
                    {
                        FkContactID = c.Int(nullable: false),
                        Evaluation = c.Int(),
                        Reputation = c.Int(),
                        Notes = c.String(maxLength: 500),
                    })
                .PrimaryKey(t => t.FkContactID)
                .ForeignKey("dbo.Contact", t => t.FkContactID)
                .Index(t => t.FkContactID);
            
            CreateTable(
                "dbo.Reminder",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Date = c.DateTime(nullable: false),
                        Hour = c.Int(),
                        Minutes = c.Int(),
                        ForewarningMin = c.Int(),
                        Notes = c.String(maxLength: 500),
                        Location = c.String(maxLength: 200),
                        Contacts_ID = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Contact", t => t.Contacts_ID)
                .Index(t => t.Contacts_ID);
            
            CreateTable(
                "dbo.Address",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        IDContacts = c.Int(nullable: false),
                        Adress = c.String(nullable: false, maxLength: 100),
                        City = c.String(nullable: false, maxLength: 50),
                        Location = c.String(nullable: false, maxLength: 30),
                        Region = c.String(maxLength: 20),
                        State = c.String(nullable: false, maxLength: 20),
                        IsDeleted = c.Boolean(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.Document",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        DocName = c.String(),
                        Type = c.String(),
                        Category = c.String(),
                        SubCategory = c.String(),
                        Tags = c.String(),
                        Doc = c.Binary(),
                        FkUserCreator = c.Int(),
                        DateCreation = c.DateTime(),
                        DateUpdated = c.DateTime(),
                        CanBeModified = c.Boolean(),
                        FkUserUpdated = c.Int(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.UserProfile",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(),
                        Message_ID = c.Int(),
                    })
                .PrimaryKey(t => t.UserId)
                .ForeignKey("dbo.Message", t => t.Message_ID)
                .Index(t => t.Message_ID);
            
            CreateTable(
                "dbo.Message",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Messaggio = c.String(nullable: false, maxLength: 600),
                        RichiediConferma = c.Boolean(nullable: false),
                        InviatoDa_UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.UserProfile", t => t.InviatoDa_UserId, cascadeDelete: true)
                .Index(t => t.InviatoDa_UserId);
            
            CreateTable(
                "dbo.AddressContact",
                c => new
                    {
                        Address_ID = c.Int(nullable: false),
                        Contact_ID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Address_ID, t.Contact_ID })
                .ForeignKey("dbo.Address", t => t.Address_ID, cascadeDelete: true)
                .ForeignKey("dbo.Contact", t => t.Contact_ID, cascadeDelete: true)
                .Index(t => t.Address_ID)
                .Index(t => t.Contact_ID);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.AddressContact", new[] { "Contact_ID" });
            DropIndex("dbo.AddressContact", new[] { "Address_ID" });
            DropIndex("dbo.Message", new[] { "InviatoDa_UserId" });
            DropIndex("dbo.UserProfile", new[] { "Message_ID" });
            DropIndex("dbo.Reminder", new[] { "Contacts_ID" });
            DropIndex("dbo.ContactProfile", new[] { "FkContactID" });
            DropForeignKey("dbo.AddressContact", "Contact_ID", "dbo.Contact");
            DropForeignKey("dbo.AddressContact", "Address_ID", "dbo.Address");
            DropForeignKey("dbo.Message", "InviatoDa_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.UserProfile", "Message_ID", "dbo.Message");
            DropForeignKey("dbo.Reminder", "Contacts_ID", "dbo.Contact");
            DropForeignKey("dbo.ContactProfile", "FkContactID", "dbo.Contact");
            DropTable("dbo.AddressContact");
            DropTable("dbo.Message");
            DropTable("dbo.UserProfile");
            DropTable("dbo.Document");
            DropTable("dbo.Address");
            DropTable("dbo.Reminder");
            DropTable("dbo.ContactProfile");
            DropTable("dbo.Contact");
        }
    }
}
